Skip to content

ch32 USBHD/USBHS driver implementation - #893

Merged
Grazfather merged 104 commits into
ZigEmbeddedGroup:mainfrom
Copper280z:ch32_usb
Jul 23, 2026
Merged

ch32 USBHD/USBHS driver implementation#893
Grazfather merged 104 commits into
ZigEmbeddedGroup:mainfrom
Copper280z:ch32_usb

Conversation

@Copper280z

@Copper280z Copper280z commented Jan 31, 2026

Copy link
Copy Markdown
Contributor

This adds a new driver for the ch32 USBHD/USBHS peripheral, USB_OTG_FS peripheral, and examples for the ch32v307, and ch32v203 boards.

@Grazfather Grazfather left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed everything except for the HALs themselves (since this is a draft). Will get to those when you think they're ready.

Comment thread core/src/core/usb.zig
Comment thread examples/wch/ch32v/build.zig
Comment thread examples/wch/ch32v/build.zig Outdated
Comment thread port/wch/ch32v/src/hals/ch32v20x.zig
Comment thread port/wch/ch32v/src/hals/ch32v30x.zig Outdated
Comment thread port/wch/ch32v/src/hals/clocks.zig
Comment thread examples/wch/ch32v/src/usb_cdc.zig Outdated
Comment thread examples/wch/ch32v/src/usb_cdc.zig
Comment thread examples/wch/ch32v/src/usb_cdc.zig Outdated
Comment thread examples/wch/ch32v/src/usb_cdc.zig Outdated
Grazfather and others added 6 commits May 30, 2026 10:39
The previous `init() Self` returned a copy of the struct, but set up DMA
in the same function, causing DMA registers to be programmed with
addresses pointing into a stack temporary.
Rewrite hw_init to follow WCH SDK init sequence with raw register
writes, fixing endpoint mode configuration (disable EP4 which shares
DMA with EP0, only enable EP1-3 needed for CDC-ACM).

Fix poll loop: mask out SOF in the ignore filter to prevent spinning,
use single-pass with early return, and add EP0 OUT re-arm after IN
completion to correctly handle SETUP toggle sequencing.
Comment thread examples/wch/ch32v/src/usb_cdc.zig Outdated
Comment thread port/wch/ch32v/src/hals/clocks.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbfs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbfs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbfs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbfs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbhs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbhs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbhs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbhs.zig Outdated
@Copper280z
Copper280z marked this pull request as ready for review July 19, 2026 03:28
Comment thread port/wch/ch32v/src/hals/usbfs.zig Outdated
Comment thread port/wch/ch32v/src/hals/usbfs.zig
Comment thread port/wch/ch32v/src/hals/usbfs.zig Outdated
@Grazfather
Grazfather requested a review from piotrfila July 22, 2026 22:35

@Grazfather Grazfather left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @piotrfila please reply to his comments, we can maybe clean up in a followup PR. Want to get this in.

@piotrfila

Copy link
Copy Markdown
Contributor

Yeah, everything's good

@Grazfather
Grazfather enabled auto-merge (squash) July 23, 2026 03:10
@Grazfather
Grazfather merged commit 0cabc4b into ZigEmbeddedGroup:main Jul 23, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants